package guda.house.web.action;

import guda.grape.util.RequestUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by well on 15/10/15.
 */
@Controller
public class IndexAction {

    @RequestMapping(value = "**/*.htm", method = RequestMethod.GET)
    public String list(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) {
        request.getSession().setAttribute("abc","123");
        if(request.getRequestURI().equals("/")){
            try {
                request.getRequestDispatcher("index.htm").forward(request, response);
            } catch (ServletException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return RequestUtil.resolveVM(request);
    }

    @RequestMapping(value = "index2.htm", method = RequestMethod.GET)
    public String list2(HttpServletRequest request, ModelMap modelMap) {
        Object abc = request.getSession().getAttribute("abc");
        modelMap.put("e", abc);

        return RequestUtil.resolveVM(request);
    }

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(HttpServletRequest request,HttpServletResponse response, ModelMap modelMap) {
       return "home/index.vm";
    }

}
